/**
 * @author: SEKin
 * @Date: 2025-04-29 09:04:40
 * @description:  promise的一些细节功能，性能上优化
 * @Last Modified time: 2025-04-29 09:04:40
 */

// Promise批处理 对于需要处理大量异步操作的场景，使用批处理而非await循环可以显著提高性能：
const processItem = () => 
  // Do something
   fetch()
;
// 低效写法
export const processItems = async  (items) => {
  const results = [];
  for (const item of items) {
    results.push(await processItem(item));
  }
  return results;
}

// 高效写法
export const  processItemsBatched = (items)=> {
  const batches = [], batchSize = 10;
  for (let i = 0; i < items.length; i += batchSize) {
    const batch = items.slice(i, i + batchSize);
    batches.push(Promise.all(batch.map((item) => processItem(item))));
  }
  return Promise.all(batches).then((batchResults) => batchResults.flat());
}

